/*******************************************************************************
 * 文件名: FileUploadProgress.java
 * 描    述: 上传进度对象类
 * 创建人: Dean Huang(hudi-112@163.com)
 * 日　期: 2017-12-22
 * 描　述: 文件描述
 * 版　本: 1.0
 *******************************************************************************/

package com.z1.core.upload;

import java.io.Serializable;

import com.z1.core.format.NumberFormat;
import com.z1.core.format.StorageUnitFormat;

public class FileUploadProgress implements Serializable {
	
	private static final long serialVersionUID = -4067529121606708505L;
	
	//已读字节 
	private long bytesRead = 0L;
	//已读MB
	private String mbRead = "0MB";
	//总长度
	private long contentLength = 0L;
	//文件编号(上传第几个文件)
	private int items;
	//已读百分比 
	private int percent;
	//读取速度
	private String speed;
	//开始读取的时间
	private long startTime = System.currentTimeMillis();
	
	public long getBytesRead() {
		return bytesRead;
	}
	public void setBytesRead(long bytesRead) {
		this.bytesRead = bytesRead;
		//percent
		if (0L != this.contentLength) {
			this.percent = (int)(((double)this.bytesRead * 100) / this.contentLength);
		}
		//mbRead
		mbRead = StorageUnitFormat.formatToFloatString(StorageUnitFormat.B, bytesRead);
		//speed
		double douSpeed  = ((double)bytesRead) / (System.currentTimeMillis() - startTime);//KB/s
		this.speed = NumberFormat.format("0.00", douSpeed) + "KB/s";
	}
	
	public String getMbRead() {
		return mbRead;
	}
	
	public long getContentLength() {
		return contentLength;
	}
	public void setContentLength(long contentLength) {
		this.contentLength = contentLength;
		if (0L != this.contentLength) {
			this.percent = (int)(((double)this.bytesRead * 100) / this.contentLength);
		}
	}
	
	public int getItems() {
		return items;
	}
	public void setItems(int items) {
		this.items = items;
	}
	
	public int getPercent() {
		return percent;
	}
	
	public String getSpeed() {
		return speed;
	}
	
	public long getStartTime() {
		return startTime;
	}
	public void setStartTime(long startTime) {
		this.startTime = startTime;
	}

}
